#!/usr/local/bin/Resource/www/cgi-bin/php
<?php
function str_between($string, $start, $end){ 
	$string = " ".$string; $ini = strpos($string,$start); 
	if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; 
	return substr($string,$ini,$len); 
}
//http://www.tele-tv.info/js/embed.js
/*
var teletv_type='emisiuni';
var teletv_width=615;
var teletv_height=315;
var teletv_id=838;
*/
//http://www.tele-tv.info/embed/' + teletv_type + '/' + teletv_id
//http://www.tele-tv.info/embed/emisiuni-link/991.swf
$link = $_GET["file"];
$html = file_get_contents($link);
$type = str_between($html,"teletv_type='","'");
$id = str_between($html,"teletv_id=",";");
$l="http://www.tele-tv.info/embed/".$type."/".$id.".swf";
if ($type=="emisiuni-link") {
$html = file_get_contents($l);
$link=trim(str_between($html,'flashvars="file=','&'));
} else {
$html = file_get_contents($l);
$l=str_between($html,'src="','&');
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $l);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
  $html = curl_exec($ch);
  curl_close($ch);
$link = str_between($html,"file: '","'");
}
print $link;
?>
